<?php
define('MINI_RUN', true);
require 'mini.php';
Mini::checkLogin();
require MINI_PATH.'admin/file.php';
$pdo = new MySQLPDO();
$now = date('Y-m-d');
$siteMap = '<?xml version = "1.0" encoding = "UTF-8"?>
<urlset xmlns = "http://www.sitemaps.org/schemas/sitemap/0.9">';
$siteMap .=  generateSiteUrl('', $now, 'weekly', '1');
$classArray = $pdo->selectSQL('SELECT ClassId,ParentClass,ClassDir FROM Mini_Class');
foreach ($classArray as $class) {
	$classurl = $class['parentclass'] ? Mini::getClassPath($class['classid']):($class['classdir'].'/');	
	$siteMap .= generateSiteUrl($classurl, $now, 'daily', '0.8');
	$pageArray = $pdo->selectSQL('SELECT PageId,filename,ModifyTime FROM Mini_Page WHERE ClassId = '.$class['classid']);
	foreach ($pageArray as $page){
		$siteMap .= generateSiteUrl($classurl.$page['filename'].'.html', date('Y-m-d',strtotime($page['modifytime'])), 'weekly','0.6');
	}	 
}
$siteMap .= '</urlset>';
createFile(MINI_PATH.'sitemap.xml', $siteMap);
echo '生成站点地图成功！';
return;

function generateSiteUrl($locurl,$modtime,$freq,$priority){
	return 
	'
   <url>
	<loc>http://'.Mini::URL.$locurl.'</loc>
      <lastmod>'.$modtime.'</lastmod>
      <changefreq>'.$freq.'</changefreq>
      <priority>'.$priority.'</priority>
   </url>
	';	
}
?>